from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.models.blog import Blog
from app.database.database import get_db

router = APIRouter()

@router.get("/blogs")
async def get_blogs(db: Session = Depends(get_db)):
    try:
        blogs = db.query(Blog).limit(10).all()
        return {"data": blogs}
    except Exception as e:
        import traceback
        traceback.print_exc()  # 打印详细错误信息
        raise HTTPException(
            status_code=500, 
            detail=f"数据库错误: {str(e)}"
        )
